#include <string>
#include <map>
#include <iostream>
#include "grammarHandler.h"
using std::multimap;
using std::string;
using std::cout; using std::endl;


// handling Chars
void GrammarHandler::operator()(const string& lastElementTag,
   const string& str) {
  if (lastElementTag == "rule"){
	  //cout<<lastNonTerminal<<endl;
	  cout<<lastNonTerminal<<","<<str<<endl;
    grammar.insert(std::pair<string, string>(lastNonTerminal, str));
  }
}

// handling Start
void GrammarHandler::operator()(const string& lastElementTag,
  const char *attr[] ) {
  for (int i = 0; attr[i]; i += 2) {
    if ( lastElementTag =="rule" && attr[i]==string("nonterminal") ) { 
      lastNonTerminal = attr[i+1];
    }
  }
}
